﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using Volo.Abp.Data;

namespace Himp.Base
{
    public static class HasExtraPropertiesExtensions
    {
        public static T Property<T>(this IHasExtraProperties source, string name)
        {
            var obj = source.GetProperty(name);

            if (obj == null)
            {
                return default;
            }

            return obj is T ? (T)obj : System.Text.Json.JsonSerializer.Deserialize<T>((JsonElement)obj);
        }
    }
}
